package ljl.codetop300;

public class _1047_remove_duplicates {

  /**
   * 我觉着不停的循环就行
   */
  static class test {
    public String removeDuplicates(String s) {
      StringBuilder sb = new StringBuilder();
      for (char c : s.toCharArray()) {
        if (last(sb) == c) {
          dec(sb);
        } else sb.append(c);
      }
      return sb.toString();
    }

    void dec(StringBuilder sb) {
      sb.setLength(sb.length() - 1);
    }
    char last(StringBuilder sb) {
      if (sb.length() == 0) return 0;
      return sb.charAt(sb.length() - 1);
    }
  }
}
